package isValidBST98;



public class IsValidBST {
    long pre = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {

        //中序遍历判断前一个节点值跟当前节点值比较
        if(root == null){
            return true;
        }
        //找左子树
        if(!isValidBST(root.left)){
            return false;
        }
        //判断当前值和前一个值
        if(root.val<=pre){
            return false;
        }
        pre = root.val;
        return isValidBST(root.right);
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
